/*
 * @Author: Leo.wang wanglizhigs@163.com
 * @Date: 2023-10-13 15:13:04
 * @LastEditors: Leo.wang wanglizhigs@163.com
 * @LastEditTime: 2024-09-03 22:57:35
 * @FilePath: /VoxGS/packages/PureK/src/convention.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

export function toUpperCase(target: string): string {
  return String.prototype.toUpperCase.call(target);
}

export function toLowerCase(target: string): string {
  return String.prototype.toLowerCase.call(target);
}

// // Hungarian strUserName
// ['str', 'User', 'Name'].join('')
// // Camel userName
// ['user', 'Name'].join('')
// // Pascal UserName
// ['User', 'Name'].join('')
// // Snake user_name
// ['user', 'name'].join('_')

export function HungarianToCamel(target: string) {
  const [, ...list] = target.split(/(?=[A-Z])/g);
  list[0] = toLowerCase(list[0]);
  return list.join('');
}
export function HungarianToPascal(target: string) {
  const [, ...list] = target.split(/(?=[A-Z])/g);
  return list.join('');
}
export function HungarianToSnake(target: string) {
  const [, ...list] = target.split(/(?=[A-Z])/g);
  return list.map(toLowerCase).join('_');
}

export function CamelToPascal(target: string): string {
  const list = target.split(/(?=[A-Z])/g);
  return list
    .map(item => item.replace(/\b\w/g, $0 => $0.toUpperCase()))
    .join('');
}
export function CamelToSnake(target: string): string {
  const list = target.split(/(?=[A-Z])/g);
  return list
    .map(item => item.replace(/\b\w/g, $0 => $0.toLowerCase()))
    .join('_');
}

export function PascalToCamel(target: string): string {
  const list = target.split(/(?=[A-Z])/g);
  list[0] = list[0].replace(/\b\w/g, $0 => $0.toLowerCase());
  return list.join('');
}
export function PascalToSnake(target: string): string {
  const list = target.split(/(?=[A-Z])/g);
  return list.map(toLowerCase).join('_');
}

export function SnakeToCamel(target: string): string {
  const list = target.split(/\_/g);
  return list
    .map((item, index) =>
      (index === 0 ? item : item.replace(/\b\w/g, $0 => $0.toUpperCase())),
    )
    .join('');
}
export function SnakeToPascal(target: string): string {
  const list = target.split(/\_/g);
  return list
    .map(item => item.replace(/\b\w/g, $0 => $0.toUpperCase()))
    .join('');
}

export const MEANS = {
  HungarianToCamel,
  HungarianToPascal,
  HungarianToSnake,
  CamelToPascal,
  CamelToSnake,
  PascalToCamel,
  PascalToSnake,
  SnakeToCamel,
  SnakeToPascal,
};


export function objKeyTransfer(target: object, manner): object {
  return Object.keys(target).reduce((acc: {}, key: string) => {
    return {
      ...acc,
      [manner(key)]: target[key],
    };
  }, {});
}
